﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assessment.Management.SharedComponent.Entities;
using Assessment.Management.SharedComponent.Params.MenuManagers;
using Assessment.Management.SharedComponent.Constants;

namespace Assessment.Management.DAO.AdminManagers
{
    public class MenuManagersDAO : BaseDaos
    {
        public MenuManagersDAO()
            : base()
        {
        }
        public void GetMenuManagers(MenuManagersParam param)
        {
            string query="";

            if (param.MenuManagers.Permission == 1)
            {
                query = "Select * from MenuManagers where MenuParentID is null";
            }
            else
            {
                query = "Select * from MenuManagers where MenuParentID is null and MenuID != 7 and MenuID != 4";
            }

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            try
            {
                param.listMenuManagers = base.ExecuteQueryGetListObject<MenuManager>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }

        public void GetChildMenu(MenuManagersParam param)
        {

            string query = "Select * from MenuManagers where MenuParentID = @MenuParentID";

            var cmd = base.GetSqlCommand();
            cmd.Parameters.AddWithValue("@MenuParentID", param.MenuManagers.MenuParentID);
            cmd.CommandText = query;
            try
            {
                param.listMenuManagers = base.ExecuteQueryGetListObject<MenuManager>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }
    }
}
